<template>
  <div
    class="ScaleBox"
    ref="ScaleBox"
    :style="{
      width: width + 'px',
      height: height + 'px',
    }"
  >
    <!-- 头部 -->
    <header></header>
    <!-- 主体 -->
    <article>
      <div class="left">
        <div class="top">
          <subTitle :subTitle="'在线企业数'"></subTitle>
        </div>
        <div class="center">
          <subTitle :subTitle="'全区能耗统计曲线'"></subTitle>
        </div>
        <div class="bottom">
          <subTitle :subTitle="'全区实时能耗概览'"></subTitle>
        </div>
      </div>
      <div class="middle"></div>
      <div class="right">
        <subTitle :subTitle="'各企业实时能耗数据'"></subTitle>
        <vue-seamless-scroll
          :data="listData"
          class="seamless-warp"
          :class-option="classOption"
        >
          <div class="item">
            <div v-for="item in listData" :key="item">
              <!-- <span class="title" v-text="item.title"></span><span class="date" v-text="item.date"></span> -->
            </div>
          </div>
        </vue-seamless-scroll>
      </div>
    </article>
  </div>
</template>
<script>
import subTitle from "../../components/subTitle/index.vue";
import vueSeamlessScroll from "vue-seamless-scroll";
export default {
  //   name: "ScaleBox",
  components: {
    subTitle,
    vueSeamlessScroll,
  },
  data() {
    return {
      scale: 0,
      width: 1920,
      height: 1080,
      listData: [],
      classOption: {},
    };
  },
  mounted() {
    this.setScale();
    window.addEventListener("resize", this.debounce(this.setScale));
  },
  methods: {
    getScale() {
      // 固定好16：9的宽高比，计算出最合适的缩放比
      //   const { width, height } = this;
      this.width = window.innerWidth;
      this.height = window.innerHeight;
      console.log(window.innerWidth);
      console.log(window.innerHeight);
      const wh = window.innerHeight / this.height;
      const ww = window.innerWidth / this.width;
      console.log(ww < wh ? ww : wh);
      return ww < wh ? ww : wh;
    },
    setScale() {
      // 获取到缩放比例，设置它
      this.scale = this.getScale();
      if (this.$refs.ScaleBox) {
        this.$refs.ScaleBox.style.setProperty("--scale", this.scale);
      }
    },
    debounce(fn, delay) {
      const delays = delay || 500;
      let timer;
      return function () {
        const th = this;
        const args = arguments;
        if (timer) {
          clearTimeout(timer);
        }
        timer = setTimeout(function () {
          timer = null;
          fn.apply(th, args);
        }, delays);
      };
    },
  },
};
</script>
<style lang="scss" scoped>
:root {
  --scale: 1;
}
.ScaleBox {
  position: absolute;
  // transform: scale(var(--scale)) translate(-50%, -50%);
  transform: scale(var(--scale));
  display: flex;
  flex-direction: column;
  transform-origin: 0 0;
  //   left: 50%;
  //   top: 50%;
  transition: 0.3s;
  z-index: 999;
  background: rgba(0, 0, 0, 0.3);
  //   border: 1px solid #f00;
  header {
    width: 100%;
    height: 52px;
    border: 1px solid #0f0;
  }
  article {
    width: 100%;
    height: calc(100% - 52px);
    // border: 1px solid #00f;
    margin-top: 20px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .left,
    .right {
      width: 450px;
      height: calc(100% - 20px);
    }
    .left {
      border: 1px solid #00f;
    }
    .middle {
      width: 900px;
      height: calc(100% - 20px);
      border: 1px solid #ff0;
    }
    .right {
      border: 1px solid #0ff;
    }
  }
  .seamless-warp {
  }
}
</style>
